package com.winbomb.kingcard.screens;

import android.util.Log;

import com.winbomb.kingcard.Action;
import com.winbomb.kingcard.Assets;
import com.winbomb.kingcard.GameMsg;
import com.winbomb.kingcard.IBattle;
import com.winbomb.kingcard.ICard;
import com.winbomb.kingcard.IPlayer;
import com.winbomb.kingcard.IState;
import com.winbomb.kingcard.KingCard;
import com.winbomb.kingcard.Pos;
import com.winbomb.kingcard.INegotiate.NegoResult;
import com.winbomb.kingcard.base.AnimManager;
import com.winbomb.kingcard.base.BattleState;
import com.winbomb.kingcard.base.GameLogic;
import com.winbomb.kingcard.base.GameState;
import com.winbomb.kingcard.base.StatsInfo;
import com.winbomb.kingcard.framework.Game;
import com.winbomb.kingcard.framework.Screen;
import com.winbomb.kingcard.framework.Input.TouchEvent;
import com.winbomb.kingcard.framework.impl.TouchArea;
import com.winbomb.kingcard.screens.util.Render;
import com.winbomb.kingcard.utils.GameUtils;

public class GameScreen extends Screen {

	public static final String TAG = "GameScreen";

	/** 每回合动作的按钮 */
	private static final TouchArea btnBattle = new TouchArea(386, 226, 40, 40);// 出征
	private static final TouchArea btnResort = new TouchArea(428, 226, 40, 40);
	private static final TouchArea btnSendOut = new TouchArea(386, 268, 40, 40);
	private static final TouchArea btnCallUp = new TouchArea(428, 268, 40, 40);
	private static final TouchArea btnTakePower = new TouchArea(386, 268, 86, 42);

	/** 确定和取消按钮 */
	private static final TouchArea btnConfirm = new TouchArea(386, 226, 86, 42);
	private static final TouchArea btnCancel = new TouchArea(386, 268, 86, 42);

	/** 菜单及其选项 */
	private static final TouchArea btnMenu = new TouchArea(356, 242, 30, 52);
	private static final TouchArea btnResume = new TouchArea(190, 66, 100, 32);
	private static final TouchArea btnRestart = new TouchArea(190, 106, 100, 32);
	private static final TouchArea btnQuit = new TouchArea(190, 202, 100, 32);
	private static final TouchArea btnMandate = new TouchArea(190, 147, 100, 32); // 托管
	private static final TouchArea btnCancelMandate = new TouchArea(385, 281, 85, 30); // 取消托管
	private static final TouchArea btnMusicOn = new TouchArea(190, 250, 35, 35);
	private static final TouchArea btnSoundOn = new TouchArea(250, 250, 35, 35);
	private static final TouchArea btnMenuOK = new TouchArea(138, 143, 85, 40);
	private static final TouchArea btnMenuCancel = new TouchArea(257, 143, 85, 40);

	/** 牌区 */
	private static final TouchArea cardsArea = new TouchArea(38, 245, 300, 70);

	private static final TouchArea reGameArea = new TouchArea(0, 0, 480, 320);
	private static final TouchArea btnOKArea = new TouchArea(185, 235, 115, 35);

	/** 交涉界面的按钮 */
	private static final TouchArea btnAgreePass = new TouchArea(145, 140, 60, 24);
	private static final TouchArea btnDenyPass = new TouchArea(280, 140, 60, 24);
	private static final TouchArea btnRequire = new TouchArea(212, 140, 60, 24);

	/** 追击是选择卡片的区域 */
	private static final TouchArea chaseCardsArea = new TouchArea(41, 247, 314, 70);

	/** 游戏结束后的按钮 */
	private static final TouchArea btnRestartGame = new TouchArea(195, 250, 92, 36); // 重新开始
	private static final TouchArea btnStatsInfo = new TouchArea(95, 250, 92, 36); // 查看战斗统计
	private static final TouchArea btnWaitHelp = btnStatsInfo; // 等待扶植
	private static final TouchArea btnBackToMenu = new TouchArea(295, 250, 92, 36); // 返回主菜单

	/** 翻页的按钮 */
	private static final TouchArea btnPageUp = new TouchArea(2, 240, 30, 40);
	private static final TouchArea btnPageDown = new TouchArea(2, 280, 30, 40);

	private GameLogic gameImpl;
	private IPlayer[] players;
	private IPlayer human;
	private IBattle battle;

	/** 用户界面的渲染 */
	private Render render;
	/** 用户动画的播放 */
	private AnimManager animMgr;

	/** 四个按钮是否可用 */
	private static final int PLAY_CARD = 0;
	private static final int CHANGE_CARD = 1;
	private static final int SEND_OUT = 2;
	private static final int TAKE_POWER = 3;
	private static final int CANCELABLE = 4;
	private boolean[] btnFlags = new boolean[] { false, false, false, false, false };

	/** 每页有多少张牌 */
	public static final int PAGE_CARDS = 10;

	/** 当前是第几页手牌 */
	private int currPage;

	/** 能否进行翻页操作 */
	private boolean canPageUp = false, canPageDown = false;

	/** 能否进行追击 */
	private boolean canChase = false;

	/** 是否在显示菜单 */
	private boolean showMenu;
	/** 是否在显示确认框 , 0表示重新开始, 1 表示退出 */
	private int showConfirm = -1;

	private static final String[] CONFIRM_MSG = new String[] { "确定重新开始吗?", "确定退出吗?" };

	public GameScreen(Game game, GameLogic gameImpl) {
		super(game);

		this.gameImpl = gameImpl;

		players = gameImpl.getPlayers();
		human = players[0];
		this.battle = gameImpl.getBattle();

		this.render = gameImpl.getRender();
		this.animMgr = gameImpl.getAnimManager();

		this.showMenu = false;
		this.showConfirm = -1;
	}

	@Override
	public void dispose() {
	}

	@Override
	public void pause() {
		gameImpl.setPause(true);
	}

	@Override
	public void present(float deltaTime) {

		// 绘制背景
		g.drawPixmap(Assets.bg, 0, 0);

		// 绘制奖金
		g.drawText("奖池: " + gameImpl.getBonus(), 320, 98, Render.BONUS_PAINT);

		// 绘制玩家
		for (int i = 0; i < players.length; i++) {
			Render.drawPlayer(players[i]);
		}

		// 绘制按钮
		drawButtons(btnFlags);

		// 绘制游戏状态
		render.drawInfoBoard();

		// 绘制游戏信息提示
		GameMsg[] msgs = gameImpl.getGameRecorder().getLastMsg(5);
		render.drawMessageBoard(msgs);

		IState gameState = gameImpl.getState();

		// 绘制手牌
		if ((gameState != BattleState.CHASE_AND_ATTACK && gameState != BattleState.SELECT_CHASE_CARDS)
				|| gameImpl.getCurrPlayer() != human) {
			drawHandCards(human.getCards(), currPage);
		} else {
			Render.drawBattleCards(human);

			// 绘制攻击对象
			Pos tgPos = battle.getLoser().getPlayerInfo().getFramePos();
			g.drawPixmap(Assets.select_frame, tgPos.x, tgPos.y, 75, 0, 75, 58);
		}

		// 绘制当前玩家
		if (gameState != GameState.GAME_START) {
			Pos tgPos = gameImpl.getCurrTurn().getPlayerInfo().getFramePos();
			g.drawPixmap(Assets.select_frame, tgPos.x, tgPos.y, 0, 0, 75, 58);
		}

		// 如果游戏结束
		if (gameImpl.isGameOver()) {
			// gameImpl.setState(GameState.VICTORY);
			// render.drawVictoryBorad(gameImpl.getWinner());

			// 游戏结束,统一者和最后一场战斗的胜者平分bonus
			int bonus = gameImpl.getBonus();
			int bonus1 = (bonus % 2 == 0) ? bonus / 2 : bonus / 2 + 1;
			gameImpl.getWinner().getStatsInfo().record(StatsInfo.ST_FINAL_SCORE, bonus1);
			battle.getWinner().getStatsInfo().record(StatsInfo.ST_FINAL_SCORE, bonus / 2);
			gameImpl.stop();
			game.setScreen(new StatsInfoScreen(game, gameImpl));
			return;
		}

		// 根据游戏的状态绘制提示信息
		if (gameImpl.getCurrPlayer().isHuman()) {
			render.drawTips();
		}

		if (gameState == GameState.SELECT_ATK_CARDS || gameState == GameState.SELECT_DEF_CARDS
				|| gameState == GameState.BEGIN_NEGOTIATE) {
			// 绘制进攻路线
			if (!battle.isStarted()) {
				render.drawAttackRoute();
			}
		}

		if (gameState == GameState.BEGIN_NEGOTIATE) {
			if (gameImpl.getCurrTurn() != human && gameImpl.getCurrPlayer().isHuman()) {
				render.drawNegotiateBoard();
			}

		} else if (gameState == GameState.SELECT_SENDOUT_CARDS) {
			// 标记出选中的派遣目标
			IPlayer tgPlayer = gameImpl.getCurrTurn().getSendTarget();
			Pos tgPos = tgPlayer.getPlayerInfo().getFramePos();
			g.drawPixmap(Assets.select_frame, tgPos.x, tgPos.y, 150, 0, 75, 58);

		} else if ((gameState == BattleState.CHASE_AND_ATTACK || gameState == BattleState.SELECT_CHASE_CARDS)
				&& gameImpl.getCurrPlayer() == human) {

			if (gameState == BattleState.CHASE_AND_ATTACK) {
				g.drawPixmap(Assets.buttons, 386, 226, 80, 160, 80, 40);
				g.drawPixmap(Assets.buttons, 386, 268, 80, 200, 80, 40);

			} else if (gameState == BattleState.SELECT_CHASE_CARDS) {
				g.drawPixmap(Assets.buttons, 386, 226, 0, (canChase) ? 80 : 120, 80, 40);
				g.drawPixmap(Assets.buttons, 386, 268, 80, 80, 80, 40);
			}
		}

		if (showConfirm != -1) {
			animMgr.play(0);
			g.drawPixmap(Assets.quit_confirm, 0, 0);
			g.drawText(CONFIRM_MSG[showConfirm], 96, 100);
		} else if (showMenu) {
			animMgr.play(0);
			g.drawPixmap(Assets.menu, 0, 0);
			g.drawPixmap(Assets.music_setting, 195, 250, 0, (KingCard.isMusicOn) ? 0 : 35, 35, 35);
			g.drawPixmap(Assets.music_setting, 250, 250, 35, (KingCard.isSoundOn) ? 0 : 35, 35, 35);
		} else {
			animMgr.play(deltaTime * 1000);
		}

	}

	@Override
	public void resume() {
		if (KingCard.isMusicOn) {
			Assets.bg_music2.play();
		}
	}

	@Override
	public void update(float deltaTime) {

		if (!showMenu) {
			gameImpl.getCurrPlayer().elapse(deltaTime);
			gameImpl.step(deltaTime);
			gameImpl.getCurrPlayer().handle();

			if (!gameImpl.isPaused() && gameImpl.getCurrPlayer().isDone()) {
				gameImpl.nextStep();
			}
		}

		// 等待人工处理的事件
		updateTouchEvents();
		for (TouchEvent event : touchEvents) {
			if (event.type != TouchEvent.TOUCH_UP) {
				continue;
			}

			// 取消托管
			if (!human.isHuman() && btnCancelMandate.isBound(event)) {
				human.setMandate(false);
				return;
			}

			/** 如果点击了菜单按钮 */
			if (btnMenu.isBound(event)) {
				showMenu = !showMenu;
				if (!showMenu) {
					showConfirm = -1;
				}
			}

			if (showConfirm != -1) {
				if (btnMenuCancel.isBound(event)) {
					showMenu = false;
					showConfirm = -1;
				}

				if (showConfirm == 0 && btnMenuOK.isBound(event)) {
					gameImpl.start();
					showMenu = false;
					showConfirm = -1;
				}

				if (showConfirm == 1 && btnMenuOK.isBound(event)) {
					Assets.bg_music2.stop();
					game.setScreen(new MainScreen(game));
				}
			}

			if (showMenu) {
				if (btnResume.isBound(event)) {
					showMenu = false;
				} else if (btnRestart.isBound(event)) {
					showConfirm = 0;
				} else if (btnMandate.isBound(event)) {
					human.setMandate(true);
					showMenu = false;
				} else if (btnQuit.isBound(event)) {
					showConfirm = 1;
				} else if (btnMusicOn.isBound(event)) {
					KingCard.isMusicOn = !KingCard.isMusicOn;
					if (KingCard.isMusicOn) {
						Assets.bg_music2.play();
					} else {
						Assets.bg_music2.stop();
					}

				} else if (btnSoundOn.isBound(event)) {
					KingCard.isSoundOn = !KingCard.isSoundOn;
				}

				return;
			}

			if (gameImpl.getCurrPlayer() != human || gameImpl.isPaused()) {
				continue;
			}

			/**
			 * 如果点了取消按钮
			 */
			if (btnFlags[CANCELABLE] && btnCancel.isBound(event)) {
				for (ICard card : human.getCards()) {
					card.setSelected(false);
				}
				human.setAttackTarget(null);
				gameImpl.setState(GameState.SELECT_ACTION);
				btnFlags[CANCELABLE] = false;
				return;
			}

			/**
			 * 点击了翻页按钮
			 */
			if (canPageUp && btnPageUp.isBound(event)) {
				currPage--;
				canPageUp = false;
			}
			if (canPageDown && btnPageDown.isBound(event)) {
				currPage++;
				canPageDown = false;
			}

			IState gameState = gameImpl.getState();

			/**
			 * 如果本局游戏结束
			 */
			if (gameState == GameState.VICTORY || gameState == GameState.DEFEATED) {
				// if (btnStatsInfo.isBound(event) && gameState ==
				// GameState.VICTORY) {
				// if (gameState == GameState.VICTORY) {
				// gameImpl.stop();
				// game.setScreen(new StatsInfoScreen(game, gameImpl));
				// return;
				// }

				if (btnRestartGame.isBound(event)) {
					gameImpl.start();
					return;
				}

				if (btnBackToMenu.isBound(event)) {
					gameImpl.stop();
					game.setScreen(new MainScreen(game));
					return;
				}

			} else if (gameState == GameState.SELECT_ACTION) {

				// 选择本轮的动作：出征、修养、扶植, 独立
				if (btnBattle.isBound(event)) {
					human.setAction(Action.BATTLE);
					btnFlags[CANCELABLE] = true;
					human.setDone(true);
				} else if (btnResort.isBound(event)) {
					human.setAction(Action.REST);
					human.setDone(true);
				} else if (human.getActionMask()[2] && btnSendOut.isBound(event)) {
					human.setAction(Action.SEND_OUT);
					btnFlags[CANCELABLE] = true;
					human.setDone(true);
				} else if (human.getActionMask()[3] && btnCallUp.isBound(event)) {
					human.setAction(Action.CALL_UP);
					btnFlags[CANCELABLE] = true;
					human.setDone(true);
				} else if (human.getActionMask()[4] && btnTakePower.isBound(event)) {
					human.setAction(Action.TAKE_POWER);
					btnFlags[TAKE_POWER] = true;
					btnFlags[CANCELABLE] = true;
					human.setDone(true);
				}

			} else if (gameState == GameState.SELECT_CHANGE_CARD) {

				// 休养，更换一张手牌
				processCardTouchEvent(event);
				btnFlags[CHANGE_CARD] = (human.getSelectedCardCount() == 1);

			} else if (gameState == GameState.SELECT_TARGET) {

				// 选择攻击的目标
				IPlayer touchedPlayer = getTouchedPlayer(event.x, event.y);
				if (touchedPlayer != null && touchedPlayer.isAlive() && touchedPlayer.getMaster() != human) {
					human.setAttackTarget(touchedPlayer);
					human.setDone(true);
				}

			} else if (gameState == GameState.SELECT_SENDOUT_TARGET) {

				// 选择派遣目标
				IPlayer touchedPlayer = getTouchedPlayer(event.x, event.y);
				if (touchedPlayer != null && (touchedPlayer.getMaster() == human || touchedPlayer.getMaster() == null)) {
					human.setSendTarget(touchedPlayer);
					human.setDone(true);
				}

			} else if (gameState == GameState.SELECT_CALLUP_SOURCE) {

				// 选择征召对象
				IPlayer touchedPlayer = getTouchedPlayer(event.x, event.y);
				if (touchedPlayer != null && touchedPlayer.isAlive() && touchedPlayer.getMaster() == human) {
					human.setCallSource(touchedPlayer);
					human.setDone(true);
				}

			} else if (gameState == GameState.SELECT_ATK_CARDS || gameState == GameState.SELECT_DEF_CARDS) {

				// 选择进攻或者防守的牌
				processCardTouchEvent(event);
				int sltCardCnt = human.getSelectedCardCount();
				btnFlags[PLAY_CARD] = (sltCardCnt >= 1 && sltCardCnt <= GameLogic.MAX_PLAY_CARD);

				// 更换进攻对象
				if (gameState == GameState.SELECT_ATK_CARDS) {
					IPlayer touchedPlayer = getTouchedPlayer(event.x, event.y);
					if (touchedPlayer != null && touchedPlayer.isAlive()) {
						human.setAttackTarget(touchedPlayer);
					}
				}

			} else if (gameState == GameState.SELECT_SENDOUT_CARDS) {

				// 选择派遣的牌
				processCardTouchEvent(event);

				// 如果派遣对象为灭亡势力,必须要三张才能复活之.
				// 如果派遣对象为存活势力,最多只能派遣两张
				int sltCardCnt = human.getSelectedCardCount();
				if (human.getSendTarget().isAlive()) {
					btnFlags[SEND_OUT] = (sltCardCnt >= 1 && sltCardCnt <= 2);
				} else {
					btnFlags[SEND_OUT] = (sltCardCnt == 3);
				}

			} else if (gameState == GameState.BEGIN_NEGOTIATE) {

				// 开始交涉
				if (btnAgreePass.isBound(event)) {
					// 同意通过
					gameImpl.getNegotiate().setResult(NegoResult.AGREE);
					human.setDone(true);
				} else if (btnDenyPass.isBound(event)) {
					// 拒绝通过
					gameImpl.getNegotiate().setResult(NegoResult.DENY);
					human.setDone(true);
				} else if (btnRequire.isBound(event)) {
					// 条件通过
					gameImpl.getNegotiate().setResult(NegoResult.REQUIRE);
					human.setDone(true);
				}

			} else if (gameState == BattleState.CHASE_AND_ATTACK) {
				if (btnConfirm.isBound(event)) {
					human.setAction(Action.CHASE_ATTACK);
					gameImpl.nextStep();
				}

				if (btnCancel.isBound(event)) {
					human.setAction(Action.WITHDRAW);
					gameImpl.nextStep();
				}

			} else if (gameState == BattleState.SELECT_CHASE_CARDS) {
				processChaseCardTouchEvent(event);
				int sltCnt = GameUtils.countSelectedCards(human.getBattleCards());
				canChase = (sltCnt >= 1 && sltCnt <= 5);

				// 点击了追击按钮
				if (canChase && btnConfirm.isBound(event)) {
					gameImpl.nextStep();
				}

				// 点击了放弃按钮
				if (btnCancel.isBound(event)) {
					gameImpl.setState(BattleState.CHASE_AND_ATTACK);
				}

			}

			// 点击了确定按钮
			if (btnConfirm.isBound(event)) {
				for (int i = 0; i < 4; i++) {
					if (btnFlags[i]) {
						btnFlags[i] = false;
						btnFlags[CANCELABLE] = false;
						currPage = 0;
						human.setDone(true);
					}
				}
			}
		}
	}

	/**
	 * 处理手牌区的点击事件
	 * 
	 * 
	 * @param event
	 */
	private void processCardTouchEvent(TouchEvent event) {
		if (!cardsArea.isBound(event)) {
			return;
		}

		int idx = getCardIndex(human.getCards(), currPage, event.x);
		if (idx < 0 || idx >= human.getCardCount()) {
			return;
		}

		ICard card = human.getCards()[idx];
		card.setSelected(card.isSelected() ? false : true);
	}

	private void processChaseCardTouchEvent(TouchEvent event) {
		if (!chaseCardsArea.isBound(event)) {
			return;
		}

		ICard card = getChaseCard(event.x);
		if (card == null) {
			return;
		}

		card.setSelected(card.isSelected() ? false : true);
	}

	/**
	 * 根据点击的坐标获取点击了哪个ChaseCard
	 * 
	 * @param x
	 * @return
	 */
	private ICard getChaseCard(int x) {
		int idx = (x - 41) / 43;

		if (idx < 0 || idx >= human.getBattleCards().size()) {
			return null;
		}

		return human.getBattleCards().get(idx);
	}

	/**
	 * 根据点击的坐标获取到点击的玩家
	 * 
	 */
	private IPlayer getTouchedPlayer(int x, int y) {

		for (int i = 1; i < players.length; i++) {
			int x0 = players[i].getPlayerInfo().getFramePos().x + 2;
			int y0 = players[i].getPlayerInfo().getFramePos().y + 2;

			if ((x > x0 && x < x0 + Render.PORT_W) && (y > y0 && y < y0 + Render.PORT_H)) {
				return players[i];
			}
		}

		return null;
	}

	/**
	 * 获取点击的牌的index
	 * 
	 * @param cards
	 * @param pageNum
	 * @param x
	 * @return
	 */
	private static int getCardIndex(ICard[] cards, int pageNum, int x) {
		// return (x - 5) / Render.PK_I - getStartIndex();

		int startIdx = pageNum * GameScreen.PAGE_CARDS;
		int endIdx = startIdx + GameScreen.PAGE_CARDS - 1;
		endIdx = (endIdx < cards.length) ? endIdx : cards.length - 1;

		int cardCnt = endIdx - startIdx + 1;
		int startPos = 4 - (cardCnt - 1) / 2;

		int offset = (x - 35) / Render.PK_I - startPos;

		//

		Log.i(TAG, "Index = " + (startIdx + offset) + ", StartIdx = " + startIdx);

		return startIdx + offset;
	}

	/**
	 * 绘制玩家的手牌（目前仅用于绘制人工玩家手中的牌）
	 * 
	 * @param player
	 */
	private void drawHandCards(ICard[] cards, int pageNum) {

		int startIdx = pageNum * GameScreen.PAGE_CARDS;
		int endIdx = startIdx + GameScreen.PAGE_CARDS - 1;
		endIdx = (endIdx < cards.length) ? endIdx : cards.length - 1;

		int cardCnt = endIdx - startIdx + 1;
		int startPos = 4 - (cardCnt - 1) / 2;

		for (int i = 0; i < cardCnt; i++) {

			int px = 35 + (startPos + i) * Render.PK_I;
			int py = (cards[startIdx + i].isSelected()) ? 244 : 248;
			Render.drawCard(cards[startIdx + i], px, py);
		}

		// 绘制换页按钮
		canPageUp = (startIdx >= GameScreen.PAGE_CARDS);
		canPageDown = (endIdx < cards.length - 1);
		g.drawPixmap(Assets.pages, 2, 240, (canPageUp) ? 0 : 30, 0, 30, 40);
		g.drawPixmap(Assets.pages, 2, 280, (canPageDown) ? 0 : 30, 40, 30, 40);
	}

	/**
	 * 绘制按钮
	 */
	public void drawButtons(boolean[] btnFlags) {

		// 托管中
		if (!human.isHuman()) {
			g.drawPixmap(Assets.buttons, 388, 228, 0, 240, 80, 80);
			return;
		}

		IPlayer currTurn = gameImpl.getCurrTurn();
		if ((!currTurn.isHuman() && !gameImpl.getCurrPlayer().isHuman()) || gameImpl.getState() == GameState.GAME_START) {
			g.drawPixmap(Assets.buttons, 386, 226, 0, 40, 40, 40);
			g.drawPixmap(Assets.buttons, 428, 226, 40, 40, 40, 40);
			if (human.getMaster() == human) {
				g.drawPixmap(Assets.buttons, 386, 268, 80, 40, 40, 40);
				g.drawPixmap(Assets.buttons, 428, 268, 120, 40, 40, 40);
			} else {
				g.drawPixmap(Assets.buttons, 386, 268, 0, 200, 80, 40);
			}

			return;
		}

		if (gameImpl.getState() == GameState.SELECT_ACTION) {

			// 出征 、修养、派遣 、征召、夺权
			// 其中派遣和征召为主公可用, 夺权为非主公可用
			g.drawPixmap(Assets.buttons, 386, 226, 0, 0, 40, 40);
			g.drawPixmap(Assets.buttons, 428, 226, 40, 0, 40, 40);
			if (human.getMaster() == human) {
				g.drawPixmap(Assets.buttons, 386, 268, 80, (currTurn.getActionMask()[2]) ? 0 : 40, 40, 40);
				g.drawPixmap(Assets.buttons, 428, 268, 120, (currTurn.getActionMask()[3]) ? 0 : 40, 40, 40);
			} else {
				g.drawPixmap(Assets.buttons, 386, 268, 0, (human.getActionMask()[4]) ? 160 : 200, 80, 40);
			}

			return;
		}

		boolean btnOKEnable = false;
		for (int i = 0; i < 4; i++) {
			if (btnFlags[i] == true) {
				btnOKEnable = true;
				break;
			}
		}

		boolean btnCancelEnable = btnFlags[4];

		// 确定、取消按钮
		g.drawPixmap(Assets.buttons, 386, 226, 0, (btnOKEnable) ? 80 : 120, 80, 40);
		g.drawPixmap(Assets.buttons, 386, 268, 80, (btnCancelEnable) ? 80 : 120, 80, 40);
	}
}
